package com.uni.action;

import com.uni.entity.User;
import com.uni.service.Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * --------------project-------------
 *
 * @Author Unirithe  - Mr.Chao
 * - CSDN:
 * https://blog.csdn.net/Unirithe
 * - GitHub:
 * https://github.com/unirithe
 * @create 2021/12/27 8:36
 * ------------------------------------------
 */
@WebServlet(name = "OrderDeleteAction", urlPatterns = "/deleteOrder")
public class OrderDeleteAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = (User) req.getSession().getAttribute("userInfo");
        Integer uid = user.getId();
        Integer cid = Integer.parseInt(req.getParameter("cid"));
        if(uid!=null && cid!=null){
            try{
                Service.order.deleteOrder(uid, cid);
                resp.getWriter().write("true");
            } catch (Exception e){
                e.printStackTrace();
                resp.getWriter().write("false");
            }
        } else{
            resp.getWriter().write("false");
        }
    }
}
